//
//  MutiChargeView.m
//  aiteshangcheng
//
//  Created by caominglei on 2018/4/24.
//  Copyright © 2018年 aite. All rights reserved.
//

#import "MutiChargeView.h"
#import "NoHighlightButton.h"
#import "UIImage+Category.h"

@implementation MutiChargeView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self createSubviews];
        [self createSubviewsFrame];
        
    }
    return self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self endEditing:YES];
    return YES;
}
- (void)createSubviews

{
    NSArray *titleArray = @[@"在线充值",@"充值明细",@"充值卡余额",@"充值卡充值"];
    for (int i = 0; i < titleArray.count; i++) {
        NoHighlightButton *selectedBtn = [NoHighlightButton buttonWithType:UIButtonTypeCustom];
        CGFloat margin = 1;
        CGFloat btnW = (kScreenWidth- 3*margin)/4;
        CGFloat btnX = i * (btnW + margin);
        selectedBtn.frame = rect(btnX, 0, btnW, 40);
        selectedBtn.tag = 1420+i;
        if (selectedBtn.tag == 1420) {
            selectedBtn.selected = YES;
            self.selectedButton = selectedBtn;
            
        }
//        else{
//            self.selectedButton.selected = NO;
//        }
        selectedBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [selectedBtn setTitle:titleArray[i] forState:UIControlStateNormal];
        [selectedBtn setBackgroundImage:[UIImage createImageWithColor:[UIColor groupTableViewBackgroundColor]] forState:UIControlStateNormal];
        [selectedBtn setBackgroundImage:[UIImage createImageWithColor:[UIColor whiteColor]] forState:UIControlStateSelected];
        [selectedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];        //        selectedBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        selectedBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:selectedBtn];
        [selectedBtn addTarget:self action:@selector(MutiBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
}

- (void)createSubviewsFrame

{
    
}

- (void)MutiBtnClicked:(UIButton *)button
{
    self.selectedButton.selected = NO;
    button.selected = YES;
    self.selectedButton = button;
    if (self.mutiBtnBlock) {
        self.mutiBtnBlock(button.tag);
    }
}
@end
